package com.mall.mapper;

import com.mall.domain.po.Review;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @description: 评论持久层
 * @author 勾新杰
 * @version 1.0
 * @date 2024/11/27 20:05
 */
@Mapper
public interface ReviewMapper {

    /**
     * 添加评论
     * @param review 评论
     */
    @Insert("insert into review (user_id, item_id, order_id, rating, comment, create_time, image) " +
            "values (#{userId}, #{itemId}, #{orderId}, #{rating}, #{comment}, #{createTime}, #{image});")
    void insert(Review review);

    /**
     * 查询商品对应所有评论
     * @param itemId 商品id
     * @return 评论列表
     */
    @Select("select id, user_id, item_id, order_id, rating, comment, image, create_time from review where item_id = #{itemId};")
    List<Review> listByItemId(Long itemId);

    /**
     * 根据id查询评论
     * @param id 评论id
     * @return 评论
     */
    @Select("select id, user_id, item_id, order_id, rating, comment, image, create_time from review where id = #{id};")
    Review getById(Long id);

    /**
     * 根据id删除评论
     * @param id 评论id
     */
    @Delete("delete from review where id = #{id};")
    void deleteById(Long id);
}
